/**
 * 系统常量定义
 */

/**
 * 系统配置常量
 */
export const SYSTEM_CONSTANTS = {
    // 默认配置
    DEFAULT_PAGE_SIZE: 20,
    MAX_PAGE_SIZE: 100,
    DEFAULT_CACHE_TTL: 300000, // 5分钟
    MAX_CACHE_SIZE: 1000,
    
    // 超时配置
    DEFAULT_TIMEOUT: 30000, // 30秒
    API_TIMEOUT: 15000, // 15秒
    DB_TIMEOUT: 10000, // 10秒
    
    // 重试配置
    MAX_RETRY_ATTEMPTS: 3,
    RETRY_DELAY: 1000,
    
    // 日志配置
    LOG_MAX_SIZE: '10MB',
    LOG_MAX_FILES: 5,
    LOG_DATE_PATTERN: 'YYYY-MM-DD',
    
    // 性能监控
    PERFORMANCE_SAMPLE_RATE: 0.1,
    SLOW_OPERATION_THRESHOLD: 1000,
} as const;

/**
 * 错误代码常量
 */
export const ERROR_CODES = {
    // 通用错误
    UNKNOWN_ERROR: 'UNKNOWN_ERROR',
    INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
    INVALID_REQUEST: 'INVALID_REQUEST',
    AUTHENTICATION_FAILED: 'AUTHENTICATION_FAILED',
    AUTHORIZATION_DENIED: 'AUTHORIZATION_DENIED',
    
    // 背包相关
    BAG_FULL: 'BAG_FULL',
    ITEM_NOT_FOUND: 'ITEM_NOT_FOUND',
    INSUFFICIENT_ITEM: 'INSUFFICIENT_ITEM',
    INVALID_ITEM_TYPE: 'INVALID_ITEM_TYPE',
    
    // RPG相关
    INSUFFICIENT_LEVEL: 'INSUFFICIENT_LEVEL',
    INVALID_EXP: 'INVALID_EXP',
    SKILL_LEARN_ERROR: 'SKILL_LEARN_ERROR',
    BATTLE_STATE_ERROR: 'BATTLE_STATE_ERROR',
    
    // 任务相关
    TASK_NOT_FOUND: 'TASK_NOT_FOUND',
    TASK_ALREADY_COMPLETED: 'TASK_ALREADY_COMPLETED',
    TASK_CONDITION_NOT_MET: 'TASK_CONDITION_NOT_MET',
} as const;

/**
 * HTTP状态码常量
 */
export const HTTP_STATUS = {
    OK: 200,
    CREATED: 201,
    ACCEPTED: 202,
    NO_CONTENT: 204,
    BAD_REQUEST: 400,
    UNAUTHORIZED: 401,
    FORBIDDEN: 403,
    NOT_FOUND: 404,
    CONFLICT: 409,
    UNPROCESSABLE_ENTITY: 422,
    INTERNAL_SERVER_ERROR: 500,
    BAD_GATEWAY: 502,
    SERVICE_UNAVAILABLE: 503,
    GATEWAY_TIMEOUT: 504,
} as const;

/**
 * 游戏相关常量
 */
export const GAME_CONSTANTS = {
    // 背包配置
    DEFAULT_BAG_SIZE: 100,
    MAX_BAG_SIZE: 200,
    MAX_ITEM_STACK: 999,
    
    // 等级配置
    MIN_LEVEL: 1,
    MAX_LEVEL: 100,
    BASE_EXP: 100,
    EXP_MULTIPLIER: 1.2,
    
    // 属性配置
    MIN_ATTRIBUTE: 1,
    MAX_ATTRIBUTE: 999,
    ATTRIBUTE_POINTS_PER_LEVEL: 5,
    
    // 技能配置
    MAX_SKILLS: 50,
    MAX_SKILL_LEVEL: 10,
    SKILL_POINTS_PER_LEVEL: 1,
    
    // 战斗配置
    BASE_HP: 100,
    BASE_MP: 50,
    BASE_ATTACK: 10,
    BASE_DEFENSE: 5,
    
    // 任务配置
    MAX_DAILY_TASKS: 10,
    MAX_WEEKLY_TASKS: 5,
    TASK_REFRESH_HOUR: 0,
    
    // 物品品质
    QUALITY_LEVELS: {
        WHITE: 1,    // 白色 - 普通
        GREEN: 2,    // 绿色 - 优秀
        BLUE: 3,     // 蓝色 - 精良
        PURPLE: 4,   // 紫色 - 史诗
        ORANGE: 5,   // 橙色 - 传说
        RED: 6,      // 红色 - 神话
    },
    
    // 装备部位
    EQUIPMENT_SLOTS: {
        WEAPON: 'weapon',
        HELMET: 'helmet',
        ARMOR: 'armor',
        PANTS: 'pants',
        SHOES: 'shoes',
        ACCESSORY: 'accessory',
    },
} as const;

/**
 * 枚举常量
 */
export const ENUMS = {
    // 匹配类型（从 face.ts 迁移）
    MATCH_TYPE: {
        EXACT: 1,      // 完全匹配
        PREFIX: 2,     // 开头匹配
        FUZZY: 3,      // 模糊匹配
        ALL: 4,        // 全部拦截
    },
    
    // 物品类型
    ITEM_TYPE: {
        CONSUMABLE: 'consumable',  // 消耗品
        EQUIPMENT: 'equipment',    // 装备
        MATERIAL: 'material',      // 材料
        QUEST: 'quest',           // 任务物品
        CURRENCY: 'currency',     // 货币
    },
    
    // 任务类型
    TASK_TYPE: {
        KILL_MONSTER: 'kill_monster',
        COLLECT_ITEM: 'collect_item',
        REACH_LEVEL: 'reach_level',
        USE_SKILL: 'use_skill',
        COMPLETE_DUNGEON: 'complete_dungeon',
    },
    
    // 任务状态
    TASK_STATUS: {
        NOT_STARTED: 'not_started',
        IN_PROGRESS: 'in_progress',
        COMPLETED: 'completed',
        CLAIMED: 'claimed',
        EXPIRED: 'expired',
    },
    
    // 角色状态
    PLAYER_STATE: {
        IDLE: 'idle',
        MOVING: 'moving',
        FIGHTING: 'fighting',
        DEAD: 'dead',
        TRADING: 'trading',
    },
    
    // 服务状态
    SERVICE_STATE: {
        CREATED: 'created',
        INITIALIZING: 'initializing',
        RUNNING: 'running',
        STOPPING: 'stopping',
        STOPPED: 'stopped',
        ERROR: 'error',
    },
} as const;

/**
 * 正则表达式常量
 */
export const REGEX_PATTERNS = {
    // 数字解析
    NUMBER: /\d+/,
    NUMBER_WITH_SUFFIX: /\d+q\d+/,
    
    // 用户输入验证
    USERNAME: /^[a-zA-Z0-9_\u4e00-\u9fa5]{2,16}$/,
    PASSWORD: /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,32}$/,
    EMAIL: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
    
    // 游戏内容验证
    ITEM_NAME: /^[\u4e00-\u9fa5a-zA-Z0-9\s]{1,20}$/,
    SKILL_NAME: /^[\u4e00-\u9fa5a-zA-Z0-9\s]{1,15}$/,
    
    // 通用格式
    UUID: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
    DATE_TIME: /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/,
    IP_ADDRESS: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
} as const;

/**
 * 消息模板常量
 */
export const MESSAGE_TEMPLATES = {
    // 成功消息
    SUCCESS: {
        ITEM_ADDED: '成功获得 {itemName} x{count}',
        LEVEL_UP: '恭喜升级！当前等级：{level}',
        TASK_COMPLETED: '任务 "{taskName}" 已完成',
        SKILL_LEARNED: '成功学习技能：{skillName}',
        EQUIPMENT_EQUIPPED: '成功装备：{equipName}',
    },
    
    // 错误消息
    ERROR: {
        BAG_FULL: '背包已满，无法添加更多物品',
        INSUFFICIENT_LEVEL: '等级不足，需要等级 {requiredLevel}',
        ITEM_NOT_FOUND: '物品不存在',
        INSUFFICIENT_RESOURCE: '{resourceName} 不足',
        OPERATION_FAILED: '操作失败：{reason}',
    },
    
    // 信息消息
    INFO: {
        PLAYER_JOINED: '{playerName} 进入了游戏',
        PLAYER_LEFT: '{playerName} 离开了游戏',
        MAINTENANCE_NOTICE: '服务器将在 {time} 进行维护',
        EVENT_STARTED: '活动 "{eventName}" 已开始',
        EVENT_ENDED: '活动 "{eventName}" 已结束',
    },
} as const;

/**
 * 配置键常量
 */
export const CONFIG_KEYS = {
    // 服务器配置
    SERVER_PORT: 'server.port',
    SERVER_HOST: 'server.host',
    
    // 数据库配置
    DB_HOST: 'database.host',
    DB_PORT: 'database.port',
    DB_NAME: 'database.name',
    DB_USER: 'database.user',
    DB_PASSWORD: 'database.password',
    
    // Redis配置
    REDIS_HOST: 'redis.host',
    REDIS_PORT: 'redis.port',
    REDIS_PASSWORD: 'redis.password',
    
    // 游戏配置
    GAME_VERSION: 'game.version',
    GAME_NAME: 'game.name',
    MAX_PLAYERS: 'game.maxPlayers',
    
    // 日志配置
    LOG_LEVEL: 'log.level',
    LOG_FILE: 'log.file',
    LOG_CONSOLE: 'log.console',
} as const;

/**
 * 事件名称常量
 */
export const EVENT_NAMES = {
    // 系统事件
    SYSTEM_STARTUP: 'system.startup',
    SYSTEM_SHUTDOWN: 'system.shutdown',
    SYSTEM_ERROR: 'system.error',
    
    // 玩家事件
    PLAYER_LOGIN: 'player.login',
    PLAYER_LOGOUT: 'player.logout',
    PLAYER_LEVEL_UP: 'player.levelUp',
    PLAYER_DEATH: 'player.death',
    
    // 背包事件
    BAG_ITEM_ADDED: 'bag.itemAdded',
    BAG_ITEM_REMOVED: 'bag.itemRemoved',
    BAG_ITEM_USED: 'bag.itemUsed',
    
    // 任务事件
    TASK_STARTED: 'task.started',
    TASK_COMPLETED: 'task.completed',
    TASK_PROGRESS_UPDATED: 'task.progressUpdated',
    
    // 战斗事件
    BATTLE_STARTED: 'battle.started',
    BATTLE_ENDED: 'battle.ended',
    BATTLE_DAMAGE_DEALT: 'battle.damageDealt',
    
    // 技能事件
    SKILL_LEARNED: 'skill.learned',
    SKILL_USED: 'skill.used',
    SKILL_UPGRADED: 'skill.upgraded',
} as const;
